import 'dart:async';
import 'package:flutter/material.dart';

class DeBouncer {
  Duration? duration;
  VoidCallback? action;
  Timer? _timer;

  DeBouncer({this.duration});

  run(VoidCallback action) {
    if (_timer != null) {
      _timer!.cancel();
    }
    _timer = Timer(duration ?? const Duration(milliseconds: 300), action);
  }
}

class SingleCall{
  static DateTime? lastPopTime;
  static call(VoidCallback action,{Duration? delayTime}){
    if(lastPopTime == null || DateTime.now().difference(lastPopTime!)> (delayTime??const Duration(seconds: 1))){
      lastPopTime = DateTime.now();
      action();
    }
  }
}

class SingleShowProgress{
  static DateTime? lastPopTime;
  static call(VoidCallback action){
    if(lastPopTime == null || DateTime.now().difference(lastPopTime!)> const Duration(seconds: 1)){
      lastPopTime = DateTime.now();
      action();
    }
  }
}